package logic

import (
	"context"
	"work-safety/model/model"

	"work-safety/workrpc/internal/svc"
	"work-safety/workrpc/workrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UploadLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogic {
	return &UploadLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UploadLogic) Upload(in *workrpc.UploadRequest) (*workrpc.UploadResponse, error) {
	// todo: add your logic here and delete this line

	var shop model.Shop
	model.DB.Debug().Where("image=?", in.Image).Find(&shop)

	shop = model.Shop{
		Phone:    in.Phone,
		Password: in.Password,
		Image:    in.Image,
		Name:     in.Name,
	}
	model.DB.Debug().Find(&shop)

	return &workrpc.UploadResponse{
		ShopId: int64(shop.ID),
	}, nil
}
